package edu.scau.divineplace.entity.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.Getter;

/**
 * @Author: x1aolone
 * @Date: 2020/8/19 21:28
 */
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum RoleTruthEnum implements BaseEnum{

    /**
     * 人物真实性
     */
    REAL(1, "真实人物"),
    VIRTUAL(0, "虚拟人物");

    /**
     * EnumValue标记数据库里面存的是type
     */
    @EnumValue
    @Getter
    private final Integer type;
    @Getter
    private final String description;

    RoleTruthEnum(Integer type, String description) {
        this.type = type;
        this.description = description;
    }

    @JsonCreator
    public static RoleTruthEnum create(String type){
        int code = Integer.parseInt(type);
        for (RoleTruthEnum value : RoleTruthEnum.values()) {
            if (value.getType() == code) {
                return value;
            }
        }
        throw new IllegalArgumentException("enum match fail");
    }

}
